package com.ecoolex.discount.sales.ws;

import com.ecoolex.discount.sales.core.manager.CardVoucherPackageManager;
import com.ecoolex.discount.sales.core.manager.DiscountOrderDetailManager;
import com.ecoolex.discount.sales.core.manager.DiscountOrderManager;
import com.ecoolex.discount.sales.core.manager.DiscountOrderRefundManager;
import com.ecoolex.discount.sales.core.manager.YouWorldGiftCardOrderManager;
import com.ecoolex.discount.sales.entity.CardVoucherPackage;
import com.ecoolex.discount.sales.entity.DiscountOrder;
import com.ecoolex.discount.sales.entity.DiscountOrderDetail;
import com.ecoolex.discount.sales.entity.DiscountOrderRefund;
import com.ecoolex.discount.sales.entity.YouWorldGiftCardOrder;
import com.ecoolex.discount.sales.pojo.CreateOrderChannelDTO;
import com.ecoolex.discount.sales.pojo.QueryDiscountOrderDTO;
import com.ecoolex.discount.sales.pojo.QueryUserDiscountOrderDTO;
import com.ecoolex.framework.common.exception.BizException;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.common.pojo.Sorting;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;

@Service
public class DiscountOrderServiceImpl implements DiscountOrderService {

    @Autowired
    private DiscountOrderManager discountOrderManager;

    @Override
    public DiscountOrder createQuotaGiftCardOrder(Integer userId, Integer productId,CreateOrderChannelDTO channel, String createUser) {
        return discountOrderManager.createQuotaGiftCardOrder(userId, productId,channel, createUser);
    }

    @Override
    public DiscountOrder createGiftCardOrder(Integer userId, Integer productId, BigDecimal faceValue,CreateOrderChannelDTO channel, String createUser) {
        return discountOrderManager.createGiftCardOrder(userId, productId, faceValue,channel, createUser);
    }

    @Override
    public DiscountOrder createVouchersOrder(Integer userId, Integer productId, Integer buyNumber,CreateOrderChannelDTO channel, String createUser) {
        return discountOrderManager.createVouchersOrder(userId, productId, buyNumber,channel, createUser);
    }

    @Override
    public boolean cancelOrder(Integer userId, Integer orderId, String updateUser) {
        return discountOrderManager.cancel(userId, orderId, updateUser);
    }

    @Override
    public boolean deleteOrder(Integer userId, Integer orderId, String updateUser) {
        return discountOrderManager.delete(userId, orderId, updateUser);
    }

    @Override
    public boolean confirmCompleteOrder(Integer userId, Integer orderId, String updateUser) {
        return discountOrderManager.confirmComplete(userId, orderId, updateUser);
    }
    
    @Override
	public boolean confirmPartCompleteOrder(Integer userId, Integer orderId, String updateUser) throws BizException {
		return discountOrderManager.confirmPartCompleteOrder(userId, orderId, updateUser);
	}

    @Override
    public Boolean refund(DiscountOrder order,Boolean cardUsed,String reasonType,String reasonComments,Boolean useBindPhone,String contactPhone, String updateUser) {
        return discountOrderManager.refund(order, cardUsed,reasonType,reasonComments,useBindPhone,contactPhone,updateUser);
    }
    
    @Override
	public Boolean cancelRefund(DiscountOrder order, String updateUser) throws BizException {
    	return discountOrderManager.cancelRefund(order, updateUser);
	}

    @Override
    public DiscountOrder getOrderById(Integer userId, Integer orderId) {
        return discountOrderManager.getById(userId, orderId);
    }

    @Override
    public DiscountOrder getOrderById(Integer orderId) {
        return discountOrderManager.getById(orderId);
    }

    @Override
    public Pagination<DiscountOrder> queryOrderByUserId(Integer userId, QueryUserDiscountOrderDTO query, Sorting[] sorts, Page page) {
        return discountOrderManager.queryByUserId(userId, query, sorts, page);
    }

    @Override
    public Pagination<DiscountOrder> query(QueryDiscountOrderDTO query, Sorting[] sorts, Page page) {
        return discountOrderManager.query(query, sorts, page);
    }

    @Autowired
    private DiscountOrderDetailManager discountOrderDetailManager;

    @Override
    public List<DiscountOrderDetail> queryOrderDetailByOrderId(Integer orderId) {
        return discountOrderDetailManager.queryByOrderId(orderId);
    }

    @Autowired
    private CardVoucherPackageManager cardVoucherPackageManager;

    @Override
    public Pagination<CardVoucherPackage> queryCardVoucherPackage(Integer userId,Page page, Integer discountMode) {
        return cardVoucherPackageManager.query(userId,page, discountMode);
    }

	@Override
	public CardVoucherPackage getCardVoucherPackage(Integer cardVoucherId, Integer userId) {
		return cardVoucherPackageManager.getCardVoucherPackage(cardVoucherId, userId);
	}

	@Autowired
	private YouWorldGiftCardOrderManager youWorldGiftCardOrderManager;
	
	@Override
	public YouWorldGiftCardOrder getByOrderId(String orderId) {
		return youWorldGiftCardOrderManager.getByOrderId(orderId);
	}

	@Autowired
	private DiscountOrderRefundManager discountOrderRefundManager;
	
	@Override
	public DiscountOrderRefund getByOrderId(Integer orderId) {
		return discountOrderRefundManager.getByOrderId(orderId);
	}

}
